package ooad.nextgen.gof.factory;

import ooad.nextgen.gof.PropertiesUtil;
import ooad.nextgen.gof.strategy.ISalePricingStrategy;


/**
 * 定价策略工厂
 * 单例模式/工厂模式
 *
 */
public class PricingStrategyFactory {
	private ISalePricingStrategy salePricingStrategy;
	public static PricingStrategyFactory instance;
	/**
	 * 得到策略工厂单例
	 * @return
	 */
	public static PricingStrategyFactory getInstance(){
		if(instance ==null){
			instance = new PricingStrategyFactory();
		}
		return instance;
	}
	/**
	 * 得到策略实例
	 * @return
	 */
	public ISalePricingStrategy getSalePricingStrategy() {
		if(salePricingStrategy==null){
			String className = PropertiesUtil.getProperty("salePricingStrategy.class.name");
			try {
				salePricingStrategy = (ISalePricingStrategy) Class.forName(className).newInstance();
			} catch (InstantiationException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			}
		}
		return salePricingStrategy;
	}
}
